package pile;

import java.util.PriorityQueue;

public class findKthLargest {
    public int findKthLargest(int[] nums, int k) {
        //小根堆
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for(int i = 0;i <k;i++) {
            q.offer(nums[i]);
        }
        for(int i = k;i<nums.length;i++) {
            if(nums[i] > q.peek()){
                q.poll();
                q.offer(nums[i]);
            }
        }
        return q.poll();
    }
}
